﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Utilities;

namespace ManageTicket.Ticket
{
    public partial class frmUpdateStatusVoucher : Form
    {
        #region Contructor
        public frmUpdateStatusVoucher(string voucher_no)
        {
            InitializeComponent();
            VOUCHER_NO = voucher_no;
        }
        #endregion

        #region Variable
        clsMethod4All objMethod = new clsMethod4All();
        ManageTicket.Library.Common.CommonFunction clsCommonFunc = new ManageTicket.Library.Common.CommonFunction();
        Business.Voucher boVoucher = new Business.Voucher();
        private string VOUCHER_NO = "";
        #endregion

        #region Event
        private void frmUpdateStatusVoucher_Load(object sender, EventArgs e)
        {
            txtVoucherNo.Text = VOUCHER_NO;
            if (txtVoucherNo.Text != "")
            {
                DataObjects.Voucher oVoucher = boVoucher.GetObjectByPK(txtVoucherNo.Text);
                if (oVoucher != null)
                {
                    if (oVoucher.Status.ToUpper() == "CURRENT")
                        cboStatus.Text = "Hiện tại";
                    else if (oVoucher.Status.ToUpper() == "FINISH")
                        cboStatus.Text = "Kết thúc";
                    else
                        cboStatus.Text = "";
                }

                LoadStatus(true);
            }
            else
                LoadStatus(false);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DataObjects.Voucher oVoucher = boVoucher.GetObjectByPK(txtVoucherNo.Text);
            if (oVoucher != null)
            {
                if (cboStatus.Text == "Hiện tại")
                    oVoucher.Status = "CURRENT";
                else if (cboStatus.Text == "Kết thúc")
                    oVoucher.Status = "FINISH";
                boVoucher.Update(oVoucher);
                MessageBox.Show("Cập nhật trạng thái vé thành công", "Aquarius", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region Method
        private void LoadStatus(bool bOK)
        {
            btnOK.Enabled = bOK;

            btnOK.ButtonColor = btnOK.Enabled ? Color.FromArgb(0, 163, 211) : Color.FromArgb(171, 171, 171);

            btnOK.ForeColor = btnOK.Enabled ? Color.FromArgb(0, 0, 0) : Color.FromArgb(241, 244, 251);
        }
        #endregion

        
    }
}
